import moment from 'moment';
import { Tooltip } from 'antd';

export const DRAWER_LIST = [];

export const TABLE_COLUMNS_LIST = ({
  showViewDrawer,
  showEditDrawer,
  onChangeTableStatus,
  handleDeleteTableRow,
  openInstanceList,
  pagination,
}) => {
  const { current, pageSize } = pagination;
  return [
    {
      name: '任务编码',
      code: 'taskId',
      width: 60,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '任务名称',
      code: 'taskName',
      width: 120,
      render: (value) => {
        return (
          (
            <Tooltip title={value}>
              <div style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
                {value}
              </div>
            </Tooltip>
          ) || '-'
        );
      },
    },
    {
      name: '执行类型名称',
      code: 'actuatorTypeName',
      width: 100,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '交易中心名称',
      code: 'tradingCenterName',
      width: 120,
      render: (value) => {
        return (
          (
            <Tooltip title={value}>
              <div style={{ whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
                {value}
              </div>
            </Tooltip>
          ) || '-'
        );
      },
    },
    {
      name: '是否重试',
      code: 'retry',
      width: 60,
      render: (value) => {
        return value ? '是' : '否';
      },
    },
    {
      name: '部署状态',
      code: 'deploymentStatus',
      width: 80,
      render: (value) => {
        return value === false ? '未部署' : '已部署';
      },
    },
    {
      name: '创建人',
      code: 'createdBy',
      width: 80,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '创建时间',
      code: 'createdAt',
      width: 120,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '操作',
      code: 'operate',
      width: 240,
      fixed: 'right',
      lock: true,
      render: (value, record, rowIndex) => {
        return (
          <div style={{ display: 'flex' }}>
            <span
              key="select"
              data-operate="operate"
              style={{
                borderRight: '1px solid var(--bd-a50)',
                paddingRight: '10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => showViewDrawer(record, rowIndex)}
            >
              {'查看'}
            </span>
            <span
              key="edit"
              data-operate="operate"
              style={{
                borderRight: '1px solid var(--bd-a50)',
                padding: '0 10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => showEditDrawer(record, rowIndex)}
            >
              {'编辑'}
            </span>
            <span
              key="del"
              data-operate="operate"
              style={{
                borderRight: '1px solid var(--bd-a50)',
                padding: '0 10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => handleDeleteTableRow(record, rowIndex)}
            >
              {'删除'}
            </span>
            <span
              key="operate"
              data-operate="operate"
              style={{
                borderRight: '1px solid var(--bd-a50)',
                padding: '0 10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => onChangeTableStatus(record, rowIndex)}
            >
              {record.deploymentStatus === false
                ? '部署'
                : record.deploymentStatus === true
                ? '取消部署'
                : '重新执行'}
            </span>
            <span
              key="list"
              data-operate="operate"
              style={{
                padding: '0 10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => openInstanceList(record, rowIndex)}
            >
              {'实例列表'}
            </span>
          </div>
        );
      },
    },
  ];
};

export const IN_TABLE_COLUMNS_LIST = ({ showViewDrawer, onInstanceClose }) => {
  return [
    {
      name: '任务实例编码',
      code: 'id',
      width: 220,
      /* render: (value, _, rowIndex) => {
        return parseInt((current - 1) * pageSize) + rowIndex + 1;
      }, */
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '执行器类型',
      code: 'actuatorTypeName',
      width: 220,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '交易中心名称',
      code: 'tradingCenterName',
      width: 220,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '数据抓取日期',
      code: 'dataGrabDate',
      width: 200,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '创建时间',
      code: 'createdAt',
      width: 200,
      render: (value) => {
        return value || '-';
      },
    },
    {
      name: '操作',
      code: 'operate',
      width: 160,
      fixed: 'right',
      lock: true,
      render: (value, record, rowIndex) => {
        return (
          <div style={{ display: 'flex' }}>
            {/*  <span
              key="select"
              data-operate="operate"
              style={{
                borderRight: '1px solid #a0a0a0',
                paddingRight: '10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => showViewDrawer(record, rowIndex)}
            >
              {'查看'}
            </span>
            <span
              key="list"
              data-operate="operate"
              style={{
                padding: '0 10px',
                height: '14px',
                display: 'flex',
                alignItems: 'center',
              }}
              onClick={() => onInstanceClose()}
            >
              {'任务管理'}
            </span> */}
            <span
              key="select"
              data-operate="operate"
              onClick={() => showViewDrawer(record, rowIndex)}
            >
              {'查看'}
            </span>
          </div>
        );
      },
    },
  ];
};
